﻿using System;
using System.IO;
using System.Linq;
using System.Reflection;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using Resn.WhuPub.BLL;
using System.Collections.Generic;
using Resn.WhuPub.DAL;
using Resn.WhuPub.DML;

namespace Resn.WhuPub.BLL
{
        /// <summary>
        /// 实现管理器的属性和方法
        /// </summary>
        public class EntityManager<E, M>  where E:Entity<M>  where M:class ,IIdentity
        {
                #region 属性

                //private List<E> _entitys; 

                /// <summary>
                /// 获取集合
                /// </summary>
                /// <value>
                /// 集合
                /// </value>
                public List<E> Entitys
                {
                        get
                        {
                                //if (_entitys == null)
                                //{
                                //        _entitys = new List<E>();

                                //        var models = DBStorage.Instance.Select<M>();

                                //        Type eType = typeof (E);

                                        
                                //        models.ForEach(i => _entitys.Add(Activator.CreateInstance(eType, i) as E));
                                        
                                //}

                                //return _entitys;


                                var result = new List<E>();

                                var models = DBStorage.Instance.Select<M>();

                                Type eType = typeof(E);


                                models.ForEach(i => result.Add(Activator.CreateInstance(eType, i) as E));

                                return result;
                        }
                }


                
                #endregion

                #region 方法

                #endregion
        }
}